<?php

namespace App\Http\Controllers\Manage;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\SuggestionsAndEvaluation;
use Illuminate\Http\Request;

class SuggestAndEvaluationController extends Controller
{
    use ResponseData;
    public function list(SuggestionsAndEvaluation $model,Request $request){

        $size = $request->input('size',10);
        if($request->filled('customer_id')){
            $model = $model->where('customer_id',$request->customer_id);
        }
        if($request->filled('customer')){
            $model = $model->where('customer','like','%'.$request->customer.'%');
        }
        $data = $model->orderBy('id','desc')->paginate($size);
        return $this->success($data);
    }
    public function store(SuggestionsAndEvaluation $model,Request $request){
        $data = $request->all();
        $model->fill($data);
        $model->save();
        return $this->success('保存成功');
    }
    public function edit(SuggestionsAndEvaluation $model,Request $request){
        if($request->filled('uuid')){
            $data = $model->where('uuid',$request->uuid)->first();
            return $this->success($data);
        }
        $data = $model->find($request->id);
        return $this->success($data);
    }
    public function update(SuggestionsAndEvaluation $model,Request $request){
        $data = $model->find($request->id);
        $data->update($request->all());
        return $this->success('修改成功');
    }
    public function destory(SuggestionsAndEvaluation $model,Request $request){
        $data = $model->find($request->id);
        $data->delete();
    }

}
